﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Reflection;
using Demo.CommonBase.Logging;
using Demo.CommonBase.Exceptions;
using Demo.Services.Contracts.DTO.Infos;
using Demo.CommonBase.DTO.Infos;
using Demo.Services.Contracts.DTO.Filters;

namespace Demo.Services.Integration.DAO.IntegrationComponents.Helpers
{
    public class TecnologyDAOHelper
    {
        /// <summary>
        /// Obtiene parametros para obtener tecnologia por id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static IList<IDbDataParameter> GetTecnologyByIdParams(int id)
        {
            IList<IDbDataParameter> result;
            SqlParameter parameter;
            try
            {
                Logger.Info(MethodInfo.GetCurrentMethod().ToString());
                result = new List<IDbDataParameter>();
                parameter = new SqlParameter("@TecnologyId", id);
                result.Add(parameter);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }

            return result;
        }
        /// <summary>
        /// Obtiene parametros para  Actualizar una Tecnologia
        /// </summary>
        /// <param name="tecnology"></param>
        /// <returns></returns>
        public static IList<IDbDataParameter> GetTecnologyUpdateParams(TecnologyInfo tecnology)
        {
            IList<IDbDataParameter> result;
            SqlParameter parameter;
            try
            {
                Logger.Info(MethodInfo.GetCurrentMethod().ToString());
                result = new List<IDbDataParameter>();
                parameter = new SqlParameter("@TecnologyId", tecnology.Id);
                result.Add(parameter);
                parameter = new SqlParameter("@Description", tecnology.Description);
                result.Add(parameter);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }

            return result;

        }

        /// <summary>
        /// Obtiene parametros para Guardar una tecnologia
        /// </summary>
        /// <param name="tecnology"></param>
        /// <returns></returns>
        public static IList<IDbDataParameter> GetTecnologySaveParams(TecnologyInfo tecnology)
        {
            IList<IDbDataParameter> result;
            SqlParameter parameter;
            try
            {
                Logger.Info(MethodInfo.GetCurrentMethod().ToString());
                result = new List<IDbDataParameter>();
                parameter = new SqlParameter("@Nombre", tecnology.Description);
                result.Add(parameter);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }

            return result;

        }
        public static IList<IDbDataParameter> GetTecnologyByPage(PaginationInfo pagin, TecnologyFilter filters)
        {
            IList<IDbDataParameter> result;
            SqlParameter parameter;
            try
            {
                Logger.Info(MethodInfo.GetCurrentMethod().ToString());
                result = new List<IDbDataParameter>();
                parameter = new SqlParameter("@Name", filters.Name);
                result.Add(parameter);                
                parameter = new SqlParameter("@Start", pagin.PageNum);
                result.Add(parameter);
                parameter = new SqlParameter("@Limit", pagin.PageSize);
                result.Add(parameter);
                parameter = new SqlParameter("@Order", pagin.Sort);
                result.Add(parameter);
                parameter = new SqlParameter("@Direction", pagin.Direction);
                result.Add(parameter);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }

            return result;
        }
        public static IList<IDbDataParameter> GetCheckNameParams(int id, string name)
        {
            IList<IDbDataParameter> result;
            SqlParameter parameter;
            try
            {
                Logger.Info();
                result = new List<IDbDataParameter>();
                parameter = new SqlParameter("@Id", id);
                result.Add(parameter);
                parameter = new SqlParameter("@Name", name);
                result.Add(parameter);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }

            return result;
        }
    }
}
